// ----------------------------------------------整体-----------------------------------

import Cookie from './cookie.js'
import Api from  './api.js'
import WApi from  '../wj/api.js'
import Base_api from "./Base_api.js";


new Vue({
    el:'#dinner',
    data(){
        return{
            tag:[],
            dinner:[],                              //显示的数据
            carezh:[],                              //关注的账号
            fanszh:[],                              //账号的粉丝
            uinfos:[],                             //当前用户的所有信息
            search:'',                            //搜索框内容
        }
    },
    methods:{
        async info(){
            let zh = sessionStorage.getItem("zh")
            let allinfo = await WApi.login()
            for(let i=0;i<allinfo.length;i++){
                if(allinfo[i].zh==zh){
                    this.uinfos=allinfo[i]
                    break
                }
            }
            //调用关注表的内容
            let careinfo = await WApi.careInfo()
            let caremsg = careinfo.data
            //获取
            for (let i=0;i<caremsg.length;i++){
                for (let j=0;j<allinfo.length;j++){
                    //关注的账号
                    if(caremsg[i].user_zh==zh){
                        if(caremsg[i].care_zh==allinfo[j].zh){
                            this.carezh.push(allinfo[j])
                        }
                    }
                    //粉丝的账号
                    if(caremsg[i].care_zh==zh){
                        if(caremsg[i].user_zh==allinfo[j].zh){
                            this.fanszh.push(allinfo[j])
                        }
                    }
                }
            }
            this.dinner=Base_api.getFanJuById(this.uinfos.id)
            this.getDate()
         },
       getDate(){
           for (let i=0;i<this.dinner.length;i++){
               var strDate=this.dinner[i].end_time
               var date = new Date()
               if(date > new Date(strDate.substring(0,19))){
                   this.tag[i]=true
               }else {
                   this.tag[i]=false
               }
           }
        },
    },
    mounted(){
        //-------------加载页面初始化数据--------------------------
        if(sessionStorage.getItem("zh")==null){
            this.$alert('请先登录', '系统提示', {
                confirmButtonText: '确定',
                callback: action => {
                    this.$message({
                        type: 'warning',
                        message: '即将跳转到登录界面...'
                    });
                    location.href='./login.html'
                }
            });
        }else {
            this.info()
        }
        //--------------------------------------------------------
    }
})


